package com.aloda.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.aloda.annotation.AdminAuthCheck;
import com.aloda.annotation.OperateLogAnno;
import com.aloda.dto.scoringResult.ScoringResultAddDTO;
import com.aloda.dto.scoringResult.ScoringResultEditDTO;
import com.aloda.query.ScoringResultPageDTO;
import com.aloda.result.PageResult;
import com.aloda.result.Result;
import com.aloda.service.ScoringResultService;
import com.aloda.vo.scoringResult.ScoringResultInfoVO;
import com.aloda.vo.scoringResult.ScoringResultPageVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("result-admin")
@RequestMapping("/admin/result")
public class ScoringResultController {

    @Resource
    private ScoringResultService scoringResultService;

    /**
     * 分页查询
     * @param scoringResultPageDTO dto
     * @return pageResult
     */
    @PostMapping("/page")
    public Result<PageResult<ScoringResultPageVO>> pageQuery(@RequestBody ScoringResultPageDTO scoringResultPageDTO) {
        PageResult<ScoringResultPageVO> pageResult = scoringResultService.pageQuery(scoringResultPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 通过id获取
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<ScoringResultInfoVO> getById(@PathVariable Long id) {
        return Result.success(BeanUtil.copyProperties(scoringResultService.getById(id), ScoringResultInfoVO.class));
    }

    /**
     * 新增评分结果
     * @param scoringResultAddDTO
     * @return
     */
    @OperateLogAnno(category = "新增评分结果")
    @PostMapping
    public Result<Long> addResult(@RequestBody ScoringResultAddDTO scoringResultAddDTO) {
        return Result.success(scoringResultService.addResult(scoringResultAddDTO));
    }

    /**
     * 删除评分结果
     * @param ids
     * @return
     */
    @AdminAuthCheck
    @OperateLogAnno(category = "删除评分结果")
    @DeleteMapping
    public Result deleteResult(@RequestBody List<Long> ids) {
        return Result.success(scoringResultService.removeByIds(ids));
    }

    /**
     * 编辑评分结果
     * @param scoringResultEditDTO
     * @return
     */
    @OperateLogAnno(category = "编辑评分结果")
    @PutMapping
    public Result editResult(@RequestBody ScoringResultEditDTO scoringResultEditDTO) {
        scoringResultService.editResult(scoringResultEditDTO);
        return Result.success();
    }

    /**
     * 导出评分结果信息表格
     * @param response
     * @param ids
     */
    @OperateLogAnno(category = "导出评分结果信息表格")
    @PostMapping("/export")
    public void exportResultToExcel(HttpServletResponse response, @RequestBody List<Long> ids) {
        scoringResultService.exportToExcel(response, ids);
    }
}
